package org.footballmanager.pandafootball.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootTax;
import org.footballmanager.pandafootball.system.form.impl.FootTaxSearchForm;
import org.footballmanager.pandafootball.system.service.FootTaxService;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Service
public class FootTaxServiceImpl extends ServiceImpl<FootTax> implements FootTaxService {
	@Override
	public double getDealTax() {
		FootTax tax = this.get(1L);
		if(tax != null){
			return tax.getFsd();
		}
		return 0D;
	}

	@Override
	public double getDismissTax() {
		FootTax tax = this.get(2L);
		if(tax != null){
			return tax.getFsd();
		}
		return 0D;
	}

    /**
     * 查询
     *
     * @param entityname        实体类名
     * @param map               参数
     * @param footTaxSearchForm 条件
     */
    @Override
    public void search(String entityname, Model map, FootTaxSearchForm footTaxSearchForm) {
        map.addAttribute(String.format(Constants.FORMNAME, entityname), footTaxSearchForm);
        Page<FootTax> page = PageHelper.startPage(footTaxSearchForm.getPageIndex(), footTaxSearchForm.getPageSize());
        List<FootTax> list = this.findall(footTaxSearchForm.buildSearchCommond());
        map.addAttribute(Constants.PI, page.toPageInfo());
        map.addAttribute(String.format(Constants.LISTENTITY, entityname), list);
    }

    /**
     * 删除所有
     *
     * @param footTaxSearchForm 条件
     * @param request           请求
     */
    @Override
    public void deleteAll(FootTaxSearchForm footTaxSearchForm, HttpServletRequest request) {
        if(footTaxSearchForm.getSelectIds() != null){
            String[] result = footTaxSearchForm.getSelectIds().split(Constants.COMMA);
            for(String id: result){
                this .delete(Long.parseLong(id), request);
            }
        }
    }
}
